var express = require('express');
var router = express.Router()
var { userModel } = require('../model/usermodel')
var { albumModel } = require('../model/album')


// 获取个人信息
router.get('/getPerson',async(req,res)=>{
    let id = req.query.id;
    let data = await userModel.find({_id:id})
    res.send({
        code: 200,
        msg: '展示个人信息',
        data
    })
})

// 修改个人信息  用户名 和 昵称
router.post('/updPerson',async(req,res)=>{
    let body = req.body;
    
    let id = body.id;
    let username = body.username;
    let nickname = body.nickname;

    // 获取个人数据
    let data = await userModel.find({_id:id})
    data = data[0]
    // 修改用户名
    data.username = username;
    // 修改昵称
    data.nickname = nickname;

    // 修改数据
    await userModel.updateOne({_id:id},data)

    res.send({
        code: 200,
        msg: '测试成功！'
    })
})


// 修改性别
router.post('/updSex',async(req,res)=>{
    let id = req.body.id;
    let gender = req.body.gender;
    await userModel.updateOne({_id:id},{gender: gender})
    
    res.send({
        code: 200,
        msg: '修改性别成功',
    })
})

// 展示出相册照片
router.get('/getAlbum',async(req, res)=>{
    let albums = await albumModel.find();

    res.send({
        code: 200,
        msg: '展示相册',
        data: albums
    })
})


router.post('/updtou',async(req,res)=>{
    let body = req.body;

    let id = body.id;
    let tou = body.tou;
    await userModel.updateOne({_id:id},{face: tou})

    res.send({
        code: 200,
        msg: '修改头像'
    })
})




module.exports = router;